package com.shanshi.activity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shanshi.activity.R;
import com.shanshi.activity.response.MyCollectInfo;

import java.util.List;

/**
 * Created by scx on 2017/3/16.
 */

public class MyCollectAdapter extends BaseAdapter {

    private Context context;
    private List<MyCollectInfo.Data> list;
    private LayoutInflater from;
    private ViewHolder holder=null;

    /*********存放店铺列表每一个item的组件类**********/
    private static class ViewHolder{
        ImageView mycollect_coverImage;   //封面图
        TextView mycollect_title;  //文章标题
        TextView mycollect_type;   //文章类型
        TextView mycollect_time;   //发布时间
        ImageView mycollect_commentImg;  //评论图片
        TextView mycollect_commentCount;  //评论数量
        ImageView mycollect_praiseImg;  //点赞图片
        TextView mycollect_praiseCount;  //点赞数量
    }

    public MyCollectAdapter(Context context, List<MyCollectInfo.Data> list) {
        from = LayoutInflater.from(context);
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null) {
            convertView=from.inflate( R.layout.mycollectitmes, null);
            holder=new ViewHolder();
            holder.mycollect_coverImage=(ImageView) convertView.findViewById(R.id.mycollect_coverImage);
            holder.mycollect_title=(TextView) convertView.findViewById(R.id.mycollect_title);
            holder.mycollect_type=(TextView) convertView.findViewById(R.id.mycollect_type);
            holder.mycollect_time=(TextView) convertView.findViewById(R.id.mycollect_time);
            holder.mycollect_commentImg=(ImageView) convertView.findViewById(R.id.mycollect_commentImg);
            holder.mycollect_commentCount=(TextView) convertView.findViewById(R.id.mycollect_commentCount);
            holder.mycollect_praiseImg=(ImageView) convertView.findViewById(R.id.mycollect_praiseImg);
            holder.mycollect_praiseCount=(TextView) convertView.findViewById(R.id.mycollect_praiseCount);
            convertView.setTag(holder);
        }else{
            holder=(ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(list.get(position).getImgUrl()).centerCrop().into(holder.mycollect_coverImage);
        holder.mycollect_title.setText(list.get(position).getTitle());
        holder.mycollect_type.setText("["+list.get(position).getArticleType()+"]");
        holder.mycollect_time.setText(list.get(position).getTime());

        holder.mycollect_commentCount.setText(list.get(position).getCommentCount()+"");
        holder.mycollect_praiseCount.setText(list.get(position).getPraiseCount()+"");

        return convertView;
    }
}
